package demo.hdz.mynotification;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hdz
 * @date 2019/02/27
 */
public class NotificationChannels {
    public final static String CRITICAL   = "critical";
    public final static String IMPORTANCE = "importance";
    public final static String DEFAULT    = "default";
    public final static String LOW        = "low";
    public final static String MEDIA      = "media";

    @RequiresApi(api = Build.VERSION_CODES.O)
    public static void createAllNotificationChannels(Context context) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if(nm == null) {
            return;
        }

        NotificationChannel mediaChannel = new NotificationChannel(MEDIA, context.getString(R.string.channel_media), NotificationManager.IMPORTANCE_DEFAULT);
        mediaChannel.setSound(null,null);
        mediaChannel.setVibrationPattern(null);

        List<NotificationChannel> channels = new ArrayList<NotificationChannel>();
        channels.add(new NotificationChannel(CRITICAL, context.getString(R.string.channel_critical), NotificationManager.IMPORTANCE_HIGH));
        channels.add(new NotificationChannel(IMPORTANCE, context.getString(R.string.channel_importance), NotificationManager.IMPORTANCE_DEFAULT));
        channels.add(new NotificationChannel(DEFAULT, context.getString(R.string.channel_default), NotificationManager.IMPORTANCE_LOW));
        channels.add(new NotificationChannel(LOW, context.getString(R.string.channel_low), NotificationManager.IMPORTANCE_MIN));
        channels.add(mediaChannel);
        nm.createNotificationChannels(channels);
    }
}
